<template>
  <div class="wrapper">
    <el-card>
      <div class="rowDiv">
        <div class="row-left">
          <div class="row-item">
            关联原料商品:<el-select
              v-model="state.waretype"
              placeholder="选择关联商品"
            >
              <el-option label="仓库1" value="001"></el-option>
              <el-option label="仓库2" value="002"></el-option>
            </el-select>
          </div>
          <div class="row-item">
            存储类型:<el-select
              v-model="state.bindstore"
              placeholder="选择存储类型"
            >
              <el-option label="门店1" value="003"></el-option>
              <el-option label="门店2" value="004"></el-option>
            </el-select>
          </div>
          <div class="row-item">
            商品类型:<el-select
              v-model="state.bindstore"
              placeholder="商品类型"
            >
              <el-option label="门店1" value="003"></el-option>
              <el-option label="门店2" value="004"></el-option>
            </el-select>
          </div>
          <div class="row-item">
            关联供应商:<el-select
              v-model="state.bindstore"
              placeholder="关联供应商"
            >
              <el-option label="门店1" value="003"></el-option>
              <el-option label="门店2" value="004"></el-option>
            </el-select>
          </div>
        </div>
        <el-button size="small" type="primary" @click="resetFields()"
          >创建仓库商品</el-button
        >
        <div class="row-right">
          <searchDiv
            :placeholder="state.placeholder"
            @searchClick="searchClick"
          ></searchDiv>
        </div>
      </div>
      <el-table :data="state.tableData" style="width: 100%">
        <el-table-column type="expand">
          <template #default="props">
            <el-form label-position="left" inline class="demo-table-expand">
              <el-form-item label="商品名称">
                <span>{{ props.row.name }}</span>
              </el-form-item>
              <el-form-item label="所属店铺">
                <span>{{ props.row.shop }}</span>
              </el-form-item>
              <el-form-item label="商品 ID">
                <span>{{ props.row.id }}</span>
              </el-form-item>
              <el-form-item label="店铺 ID">
                <span>{{ props.row.shopId }}</span>
              </el-form-item>
              <el-form-item label="商品分类">
                <span>{{ props.row.category }}</span>
              </el-form-item>
              <el-form-item label="店铺地址">
                <span>{{ props.row.address }}</span>
              </el-form-item>
              <el-form-item label="商品描述">
                <span>{{ props.row.desc }}</span>
              </el-form-item>
            </el-form>
          </template>
        </el-table-column>
        <el-table-column label="商品编码" prop="id"> </el-table-column>
        <el-table-column label="商品图" prop="name"> </el-table-column>
        <el-table-column label="仓库商品名称" prop="name"> </el-table-column>
        <el-table-column label="关联原料商品" prop="name"> </el-table-column>
        <el-table-column label="关联供应商" prop="name"> </el-table-column>
        <el-table-column label="规格" prop="name"> </el-table-column>
        <el-table-column label="进价" prop="name"> </el-table-column>
        <el-table-column label="售价" prop="name"> </el-table-column>
        <el-table-column label="库存" prop="name"> 
          <template v-slot="scope">
              <el-button type="text" @click="state.detaildrawer=true;">库存</el-button>
          </template>
        </el-table-column>
        <el-table-column label="存储类型" prop="name"> </el-table-column>
        <el-table-column label="商品类型" prop="name"> </el-table-column>
        <el-table-column label="分类" prop="name"> </el-table-column>
        <el-table-column label="上架" prop="name"> </el-table-column>
        <el-table-column label="操作" prop="desc"> </el-table-column>
      </el-table>
      <!-- 新建仓库 -->
      <el-dialog
        title="新建仓库"
        v-model="state.new_dialogVisible"
        width="25%"
        center
      >
        <span>
          <el-form
            :model="state.set_form"
            :rules="state.rules"
            ref="form"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="上级仓库" prop="last_ware">
              <el-select
                v-model="state.set_form.last_ware"
                placeholder="请选择上级仓库"
              >
                <el-option label="区域一" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="仓库名称" prop="ware_name">
              <el-input v-model="state.set_form.ware_name"></el-input>
            </el-form-item>
            <el-form-item label="所属人" prop="belong_man">
              <el-select
                v-model="state.set_form.belong_man"
                placeholder="请选择所属人"
              >
                <el-option label="区域一" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="关联物流商" prop="relate_log">
              <el-select
                v-model="state.set_form.relate_log"
                placeholder="请选择物流商"
              >
                <el-option label="区域一" value="shanghai"></el-option>
                <el-option label="区域二" value="beijing"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="联系人" prop="contact_man">
              <el-input v-model="state.set_form.contact_man"></el-input>
            </el-form-item>
            <el-form-item label="联系电话" prop="contact_phone">
              <el-input v-model="state.set_form.contact_phone"></el-input>
            </el-form-item>
            <el-form-item label="仓库地址" prop="ware_address">
              <el-input
                type="textarea"
                v-model="state.set_form.ware_address"
              ></el-input>
            </el-form-item>
          </el-form>
        </span>
        <template #footer>
          <span class="dialog-footer">
            <el-button @click="close()">取 消</el-button>
            <el-button type="primary" @click="create_ware()">确 定</el-button>
          </span>
        </template>
      </el-dialog>
      <!-- 创建 -->
      <el-drawer
        size="60%"
        title="创建商品"
        v-model="state.drawer"
        :direction="direction"
        :before-close="handleClose"
        destroy-on-close
      >
        <div class="contxt">
          <div>1、选择供应商</div>
          <div class="row-item">
            关联供应商:<el-select
              v-model="state.bindstore"
              multiple
              placeholder="关联供应商"
            >
              <el-option label="门店1" value="003"></el-option>
              <el-option label="门店2" value="004"></el-option>
            </el-select>
          </div>
          <div>2、选择原料产品</div>
          <div class="rowDiv" style="flex-wrap: wrap">
            <div class="row-item">
              原料商品名称:<el-select
                v-model="state.bindstore"
                placeholder="原料商品名称"
              >
                <el-option label="门店1" value="003"></el-option>
                <el-option label="门店2" value="004"></el-option>
              </el-select>
            </div>
            <div class="row-item">
              原料商品编码:<el-input
                v-model="state.bindstore"
                placeholder="原料商品编码"
              ></el-input>
            </div>
            <div class="row-item">
              原料商品箱规:<el-input
                v-model="state.bindstore"
                placeholder="原料商品箱规"
              ></el-input>
            </div>
            <div class="row-item">
              原料商品箱重:<el-input
                v-model="state.bindstore"
                placeholder="原料商品箱重"
              ></el-input>
            </div>
            <div class="row-item">
              原料商品规格:<el-input
                v-model="state.bindstore"
                placeholder="原料商品规格"
              ></el-input>
            </div>
            <div class="row-item">
              计费方式:<el-input
                v-model="state.bindstore"
                placeholder="计费方式"
              ></el-input>
            </div>
          </div>
          <div>3、创建仓库商品</div>
          <el-table :data="state.addTb" style="width: 100%">
            <el-table-column label="日期" width="180">
              <template #default="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">{{ scope.row.date }}</span>
              </template>
            </el-table-column>
            <el-table-column label="姓名" width="180">
              <template #default="scope">
                <el-popover effect="light" trigger="hover" placement="top">
                  <template #default>
                    <p>姓名: {{ scope.row.name }}</p>
                    <p>住址: {{ scope.row.address }}</p>
                  </template>
                  <template #reference>
                    <div class="name-wrapper">
                      <el-tag size="medium">{{ scope.row.name }}</el-tag>
                    </div>
                  </template>
                </el-popover>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template #default="scope">
                <el-button
                  size="mini"
                  @click="handleEdit(scope.$index, scope.row)"
                  >编辑</el-button
                >
                <el-button
                  size="mini"
                  type="danger"
                  @click="handleDelete(scope.$index, scope.row)"
                  >删除</el-button
                >
              </template>
            </el-table-column>
          </el-table>
          <el-button type="primary">添加商品</el-button>

          <div class="rowDiv" style="margin: auto; width: 50px">
            <el-button>取消</el-button>
            <el-button type="primary">提交</el-button>
          </div>
        </div>
      </el-drawer>
      <!-- 查看库存 -->
      <el-drawer
        size="40%"
        title="库存详情"
        v-model="state.detaildrawer"
        :direction="direction"
        :before-close="handleClose"
        destroy-on-close
      >
        <div class="contxt">
          <div>原料商品库存信息</div>
          <el-table :data="state.t1" style="width: 100%">
            <el-table-column prop="date" label="日期" width="180">
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="180">
            </el-table-column>
            <el-table-column prop="address" label="地址"> </el-table-column>
          </el-table>
          <div>仓库商品库存信息</div>
          <el-table :data="state.t1" style="width: 100%">
            <el-table-column prop="date" label="日期" width="180">
            </el-table-column>
            <el-table-column prop="name" label="姓名" width="180">
            </el-table-column>
            <el-table-column prop="address" label="地址"> </el-table-column>
          </el-table>
        </div>
      </el-drawer>
    </el-card>
  </div>
</template>

<script>
import { ref, reactive } from "vue";
import { useRouter } from "vue-router";
import searchDiv from "@/components/Search.vue";
export default {
    name:"ware_pro_manager",
  components: { searchDiv },
  props: {},
  setup() {
    let form = ref("null");
    const router = useRouter();
    let state = reactive({
      drawer: false,
      detaildrawer: false,
      placeholder: "请输入您要搜索的内容",
      searchval: "",
      order_dialogVisible: false,
      wareparent: "",
      waretype: "",
      bindstore: "",
      set_form: {
        last_ware: "",
        ware_name: "",
        belong_man: "",
        relate_log: "",
        contact_man: "",
        contact_phone: "",
        ware_address: "",
      },
      rules: {
        last_ware: [
          { required: true, message: "请选择上级仓库", trigger: "change" },
        ],
        ware_name: [
          { required: true, message: "请填写仓库名称", trigger: "blur" },
        ],
        belong_man: [
          { required: true, message: "请选择所属人", trigger: "change" },
        ],
        relate_log: [
          { required: true, message: "请选择物流商", trigger: "change" },
        ],
        contact_man: [
          { required: true, message: "请填写联系人", trigger: "blur" },
        ],
        contact_phone: [
          { required: true, message: "请填写联系电话", trigger: "blur" },
        ],
        ware_address: [
          { required: true, message: "请填写仓库地址", trigger: "blur" },
        ],
      },
      t1: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
      addTb: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
      tableData: [
        {
          id: "12987122",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
        },
        {
          id: "12987123",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
        },
        {
          id: "12987125",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
        },
        {
          id: "12987126",
          name: "好滋好味鸡蛋仔",
          category: "江浙小吃、小吃零食",
          desc: "荷兰优质淡奶，奶香浓而不腻",
          address: "上海市普陀区真北路",
          shop: "王小虎夫妻店",
          shopId: "10333",
        },
      ],
      current_pro_arr: [
        {
          date: "2016-05-02",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1518 弄",
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1517 弄",
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1519 弄",
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          address: "上海市普陀区金沙江路 1516 弄",
        },
      ],
    });
    function searchClick(searchCon) {
      console.log("子组件", searchCon);
    }
    // 通过审核
    function allow_order() {
      state.order_dialogVisible = false;
    }
    // 重置
    function resetFields() {
      state.drawer = true;
    }
    // 关闭弹窗--并清除表单信息
    function close() {
      form.value.resetFields();
      state.order_dialogVisible = false;
    }
    // 编辑
    function editRow() {
      state.order_dialogVisible = true;
    }
    // 查看详情
    function detailRow(idx, data) {
      console.log(idx.row.date);
      router.push({ path: "/order_detail", query: { id: idx.row.date } });
    }
    // 删除
    function deleteRow(index, rows) {
      if (confirm("是否要取消?")) {
      }
    }
    // 打开新建弹窗
    function new_set_ware() {
      state.new_dialogVisible = true;
    }
    function create_ware() {
      form.value.validate((valid) => {
        if (valid) {
          alert("submit!");
          close();
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    }
    // 创建仓库
    return {
      searchClick,
      form,
      state,
      resetFields,
      editRow,
      detailRow,
      deleteRow,
      new_set_ware,
      close,
      create_ware,
      allow_order,
    };
  },
};
</script>
<style lang="scss" scoped>
.wrapper {
  height: 100%;
  .el-card {
    height: 100%;
    .contxt {
      padding: 10px;
      box-sizing: border-box;
    }
    .cart-title::before {
      content: " ";
      width: 4px;
      height: 20px;
      background: #1890ff;
      background: #1890ff;
      display: inline-block;
      vertical-align: middle;
      margin-right: 5px;
    }
    .rowDiv {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 20px;
      width: 100%;
      .row-left {
        display: flex;
        width: 70%;
        justify-content: space-between;
        .row-item {
          display: flex;
          margin-right: 30px;
          align-items: center;
          white-space: nowrap;
        }
      }
      .row-right {
        width: 15%;
        display: flex;
        justify-content: flex-end;
      }
    }
    .el-table /deep/ th {
      background-color: #eaeaea;
      text-align: center;
    }
    .el-table /deep/ td {
      text-align: center;
    }
    .el-select {
      width: 100%;
    }
  }
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
}
</style>